<?php

namespace app\api\controller;


use think\Db;

use app\common\helper\MyHelper;
use think\Controller;
use think\Loader;
use  app\api\controller\Job;
// 读excel


class Zstpobtainqueue
{

    protected $model_name = "";

    protected $ip = "";
    protected $article_id = "";
    protected $queue_id = "";
    protected $dh = "";
    protected $wjbh = "";

    protected $insertArr = [];
    protected $ollamaIp = "";
    protected $qzh = "";
    protected $chouData = [];


    function index()
    {
        


        $ollamaId = $_GET['ollamaid'];

        //查询ollama信息
        $ollamaResult = Db::table('zstp_ollama')->where(array("id" =>  $ollamaId))->find();
        if(empty($ollamaResult)){
            return json(['code' => 0, 'msg' => 'ollama不存在']);
        }
       
        $this->ollamaIp = $ollamaResult['ip'];
        $this->model_name = $ollamaResult['model_name'];

       
        // 开启事务
        Db::startTrans();
        try {
            //查任务的信息
            $map['status'] = 0;
            $map['is_delete'] = 0;
            $obtainResult = Db::table('zstp_obtain')->where($map)->order('id asc')->find();

            if (empty($obtainResult)) {
                Db::rollback();
                sleep(10);
                return json(['code' => 0, 'msg' => '任务不存在']);
            }

    
            $mapque['obtain_id'] = $obtainResult['id'];
            $mapque['status'] = 0;
            $mapque['is_delete'] = 0;

            // $mapque['id'] = 30;
        
        

            //
            $obtainQueueResult = Db::table('zstp_obtain_queue')
                ->where($mapque)
                ->find();


            if (empty($obtainQueueResult)) {
                //更新任务结束
                    Db::table('zstp_obtain')->where('id', $obtainResult['id'])->update(['status' => 1]);
                    Db::commit();
                    sleep(10);
                    return json(['code' => 0, 'msg' => '暂无需要处理的数据']);
                }


            $time1 =time();
              

            if(!empty($obtainQueueResult)){
                $updateCount  = Db::table('zstp_obtain_queue')
                ->where('id', $obtainQueueResult['id'])
                ->where('status', 0)
                ->update(['status' => 2]);
                Db::commit();
                if ($updateCount == 0) {
                    Db::rollback();
                    sleep(10);
                    return json(['code' => 0, 'msg' => '队列已经执行']);
                }
            }    
          

    
            $this->article_id = $obtainQueueResult['article_id'];
            $this->queue_id =  $obtainQueueResult['id'];
        


            // 处理数据
            $result = $this->work($obtainQueueResult);
            $time2 =time();
            $miaocha = $time2 - $time1;
            //  $time  转成分钟
          
    
            // 根据处理结果更新最终状态
            if ($result) {
                if(empty($this->chouData)){
                    $this->chouData="";
                }else{
                    $this->chouData=json_encode($this->chouData, JSON_UNESCAPED_UNICODE);
                }
                // 处理成功
                Db::table('zstp_obtain_queue')
                    ->where('id', $obtainQueueResult['id'])
                    ->update([
                        'text' => $this->chouData,
                        "running_time" => $miaocha,
                        'status' => 1,
                        'finish_time' => date('Y-m-d H:i:s')
                    ]);

             Db::table('zstp_obtain_queue_lock')->insert(array(
                'queue_id' => $this->queue_id,
             ));      
                   // 提交事务
            Db::commit();     
            } else {
                // 处理失败，重置状态
                Db::table('zstp_obtain_queue')
                    ->where('id', $obtainQueueResult['id'])
                    ->update([
                        'running_time' => $miaocha,
                        'status' => 3,
                        'error_count' => Db::raw('error_count+1'),
                        'last_error_time' => date('Y-m-d H:i:s')
                    ]);
                    Db::rollback();
            }

            return json(['code' => 1, 'msg' => '处理成功']);
        } catch (\Exception $e) {
            // 发生异常时回滚事务
            Db::rollback();
            return json(['code' => -1, 'msg' => $e->getMessage()]);
        }
    }


    function  work($obtainQueueResult)
    {
        try {


            $article = Db::table('zstp_article')->where('id', $this->article_id)->find();

            var_dump($article);
            

            $this->dh = $article['dh'];
            $this->wjbh = $article['wjbh'];
            $content = $article['content']; // var_dump($article);
            $this->qzh = $article['qzh'];


            $filterResult = $this->filter($article);

            if($filterResult){
                return true;
            }

            $Job = new \app\api\controller\Job();

            //查出所有的模板
            $mapTemp['is_delete'] = 0;
            $mapTemp['status'] = 1;
            $templateResult = Db::table('zstp_template')->where($mapTemp)->select();

            // die();
            //遍历模板
            foreach ($templateResult as $key => $value) {

                //查出模板的判定特征
                $templateArr = [];
                // $value['identifying_features'] = json_encode($value['identifying_features'], JSON_UNESCAPED_UNICODE);
                $templateArr[] = $value;
                $resultTem = $Job->forTemplateArr($templateArr, $article);

                if (!empty($resultTem['template_id'])) {
                    var_dump("命中模版id:" . $resultTem['template_id']);
                }



                if (!empty($resultTem['template_id'])) {
                    // 匹配到模版 走ollama

                    // 获取模版特征
                    $cueWord = $value['persondesc']
                        . "以下是文章正文：
                $content 
              ";


       

                    // die();
                    //请求ollama
                    // $data = $this->ollama($cueWord);

                    $data = $this->onlineOllama($cueWord);


                    //   var_dump($data);
                    // 格式化ollama返回的数据
                    // $dataArr = $this->ollamaDataformat($data);

                    $dataArr = $this->onlineOllamaDataformat($data);
                    



                    $type = $dataArr['type'];
                    $data = $dataArr['data'];



                    //   var_dump($data);

                    if ($type == "personnel") {

                        //加上异常
                        try {
                            $this->personnel($data);
                        } catch (\Exception $e) {
                            var_dump($e->getMessage());
                            // die();
                            return false;
                        }
                    }

                    if ($type == "organization") {
                        try {
                            $this->organization($data);
                        } catch (\Exception $e) {
                            var_dump($e->getMessage());
                            // die();
                            return false;
                        }
                    }

                    if ($type == "position_event") {
                        try {
                            $this->position_event($data);
                        } catch (\Exception $e) {
                            var_dump($e->getMessage());
                            // die();
                            return false;
                        }
                    }

                    if ($type == "rank_event") {
                        try {
                            $this->rank_event($data);
                        } catch (\Exception $e) {
                            var_dump($e->getMessage());
                            // die();
                            return false;
                        }
                    }

                    if ($type == "social_relations") {
                        try {
                            $this->social_relations($data);
                        } catch (\Exception $e) {
                            var_dump($e->getMessage());
                            // die();
                            return false;
                        }
                    }

                    if ($type == "abroad_event") {
                        try {
                            $this->abroad_event($data);
                        } catch (\Exception $e) {
                            var_dump($e->getMessage());
                            // die();
                            return false;
                        }
                    }

                    if ($type == "historical_evolution") {
                        try {
                            $this->historical_evolution($data);
                        } catch (\Exception $e) {
                            var_dump($e->getMessage());
                            // die();
                            return false;
                        }
                    }

                    if ($type == "rewards_punishments_event") {
                        try {
                            $this->rewards_punishments_event($data);
                        } catch (\Exception $e) {
                            var_dump($e->getMessage());
                            // die();
                            return false;
                        }
                    }

                    if ($type == "significant_events") {
                        try {
                            $this->significant_events($data);
                        } catch (\Exception $e) {
                            var_dump($e->getMessage());
                            // die();
                            return false;
                        }
                    }

                    if ($type == "rewards") {
                        try {
                            $this->rewards($data);
                        } catch (\Exception $e) {
                            var_dump($e->getMessage());
                            // die();
                            return false;
                        }
                    }
                }
            }
            // 处理队列逻辑
            // ...
            return true;
        } catch (\Exception $e) {

            var_dump($e->getMessage());
            // die();
            return false;
        }
    }
    //科技奖励
    function rewards($data)
    {

        foreach ($data as $key => $value) {
            if (empty($value['personal_name']) || !checkFields($value['personal_name'])) {

                echo "";
            } else {
                $insertArr = [];

                $subject_nameArr = explode(",", $value['personal_name']);



                foreach ($subject_nameArr as $key => $v) {
                    $insert = [];
                    $insert['article_id'] = $this->article_id;
                    $insert['queue_id'] = $this->queue_id;
                    $insert['qzh'] = $this->qzh;
                    $insert['dh'] = $this->dh;
                    $insert['wjbh'] = $this->wjbh;
                    $count = 0;

                    $insert['subject_name'] = $v;

                    $insert['ranking'] = '';
                    if (!empty($value['ranking']) && checkFields($value['ranking'])) {
                        $insert['ranking'] = $value['ranking'];
                        $count++;
                    }

                    $insert['reward_name'] = '';
                    if (!empty($value['reward_name']) && checkFields($value['reward_name'])) {
                        $insert['reward_name'] = $value['reward_name'];
                        $count++;
                    }

                    $insert['project_name'] = '';
                    if (!empty($value['project_name']) && checkFields($value['project_name'])) {
                        $insert['project_name'] = $value['project_name'];
                        $count++;
                    }
         
           

                    $insert['reason'] = '';
                    if (!empty($value['reason']) && checkFields($value['reason'])) {
                        $insert['reason'] = $value['reason'];
                        $count++;
                    }

                    $insert['issuer'] = '';
                    if (!empty($value['issuer']) && checkFields($value['issuer'])) {
                        $insert['issuer'] = $value['issuer'];
                        $count++;
                    }
                    $insert['event_date'] = '';
                    if (!empty($value['event_date']) && checkFields($value['event_date'])) {
                        $insert['event_date'] = $value['event_date'];
                        $count++;
                    }
                    $insert['type'] = '1';

                    if ($count >= 1) {
                        $insertArr[] = $insert;
                    }

    
                }

                $this->chouData["科技奖励-个人"] = $insertArr;

                Db::table('zstp_neo4j_rewards')->insertAll($insertArr);
            }

            if (empty($value['organization_name']) || !checkFields($value['organization_name'])) {

                echo "";
            } else {

                $insertArr = [];

                $subject_nameArr = explode(",", $value['organization_name']);
       
                foreach ($subject_nameArr as $key => $v) {
                    $insert = [];
                    $insert['article_id'] = $this->article_id;
                    $insert['queue_id'] = $this->queue_id;
                    $insert['qzh'] = $this->qzh;
                    $insert['dh'] = $this->dh;
                    $insert['wjbh'] = $this->wjbh;
                    $count = 0;

                    $insert['subject_name'] = $v;

                 
                    $insert['reward_name'] = '';
                    if (!empty($value['reward_name']) && checkFields($value['reward_name'])) {
                        $insert['reward_name'] = $value['reward_name'];
                        $count++;
                    }

                    $insert['project_name'] = '';
                    if (!empty($value['project_name']) && checkFields($value['project_name'])) {
                        $insert['project_name'] = $value['project_name'];
                        $count++;
                    }

                    $insert['ranking'] = '';
                    if (!empty($value['ranking']) && checkFields($value['ranking'])) {
                        $insert['ranking'] = $value['ranking'];
                        $count++;
                    }

                    $insert['reason'] = '';
                    if (!empty($value['reason']) && checkFields($value['reason'])) {
                        $insert['reason'] = $value['reason'];
                        $count++;
                    }

                    $insert['issuer'] = '';
                    if (!empty($value['issuer']) && checkFields($value['issuer'])) {
                        $insert['issuer'] = $value['issuer'];
                        $count++;
                    }
                    $insert['event_date'] = '';
                    if (!empty($value['event_date']) && checkFields($value['event_date'])) {
                        $insert['event_date'] = $value['event_date'];
                        $count++;
                    }
                    $insert['type'] = '2';

                    if ($count >= 1) {
                        $insertArr[] = $insert;
                    }
                }
                $this->chouData["科技奖励-组织"] = $insertArr;

                Db::table('zstp_neo4j_rewards')->insertAll($insertArr);
            }
        }
        return ['code' => 200, 'msg' => '处理成功'];
    }

    // 重大事件
    function significant_events($data)
    {


        foreach ($data as $key => $value) {
            $insertArr = [];

            $insert['article_id'] = $this->article_id;
            $insert['queue_id'] = $this->queue_id;
            $count = 0;
            if (empty($value['participants'])) {

                return ['code' => 400, 'msg' => '人员名称不能为空'];
            }
            $participantsArr =  $value['participants'];

            foreach ($participantsArr as $key => $v) {
                $insert = [];

                $insert['article_id'] = $this->article_id;
                $insert['queue_id'] = $this->queue_id;
                $insert['qzh'] = $this->qzh;
                $insert['dh'] = $this->dh;
                $insert['wjbh'] = $this->wjbh;
                $count = 0;
                $insert['participants'] = $v;
                if (!empty($value['unit_name']) && checkFields($value['unit_name'])) {
                    $insert['unit_name'] = $value['unit_name'];
                    $count++;
                }
                $insert['event_title'] = '';
                if (!empty($value['event_title']) && checkFields($value['event_title'])) {
                    $insert['event_title'] = $value['event_title'];
                    $count++;
                }
                $insert['event_date'] = '';
                if (!empty($value['event_date']) && checkFields($value['event_date'])) {
                    $insert['event_date'] = $value['event_date'];
                    $count++;
                }
                $insert['description'] = '';
                if (!empty($value['description']) && checkFields($value['description'])) {
                    $insert['description'] = $value['description'];
                    $count++;
                }

                $insert['type'] = '';
                if (!empty($value['type']) && checkFields($value['type'])) {
                    $insert['type'] = $value['type'];
                    $count++;
                }
                $insert['impact'] = '';
                if (!empty($value['impact']) && checkFields($value['impact'])) {
                    $insert['impact'] = $value['impact'];
                    $count++;
                }
                $insert['note'] = '';
                if (!empty($value['note']) && checkFields($value['note'])) {
                    $insert['note'] = $value['note'];
                    $count++;
                }
                $insert['location'] = '';
                if (!empty($value['location']) && checkFields($value['location'])) {
                    $insert['location'] = $value['location'];
                    $count++;
                }
                


                if ($count >= 1) {
                    $insertArr[] = $insert;
                }
            }
            
            $this->chouData["机构大事记抽取结果"] = $insertArr;

            Db::table('zstp_neo4j_significant_events')->insertAll($insertArr);
        }
    }

    // 奖惩事件
    function rewards_punishments_event($data)
    {

        foreach ($data as $key => $value) {
            if (empty($value['personal_name']) || !checkFields($value['personal_name'])) {

                echo "";
            } else {
                $insertArr = [];

                $subject_nameArr = explode(",", $value['personal_name']);

                foreach ($subject_nameArr as $key => $v) {
                    $insert = [];
                    $insert['article_id'] = $this->article_id;
                    $insert['queue_id'] = $this->queue_id;
                    $insert['qzh'] = $this->qzh;
                    $insert['dh'] = $this->dh;
                    $insert['wjbh'] = $this->wjbh;
                    $count = 0;

                    $insert['subject_name'] = $v;

                    $insert['event_type'] = '';
                    if (!empty($value['event_type']) && checkFields($value['event_type'])) {
                        $insert['event_type'] = $value['event_type'];
                        $count++;
                    }
                    $insert['summary'] = '';
                    if (!empty($value['summary']) && checkFields($value['summary'])) {
                        $insert['summary'] = $value['summary'];
                        $count++;
                    }

                    $insert['reason'] = '';
                    if (!empty($value['reason']) && checkFields($value['reason'])) {
                        $insert['reason'] = $value['reason'];
                        $count++;
                    }

                    $insert['issuer'] = '';
                    if (!empty($value['issuer']) && checkFields($value['issuer'])) {
                        $insert['issuer'] = $value['issuer'];
                        $count++;
                    }
                    $insert['event_date'] = '';
                    if (!empty($value['event_date']) && checkFields($value['event_date'])) {
                        $insert['event_date'] = $value['event_date'];
                        $count++;
                    }
                    $insert['type'] = '1';

                    if ($count >= 1) {
                        $insertArr[] = $insert;
                    }

                    var_dump($insertArr);
                }
                $this->chouData["奖惩抽取结果-个人"] = $insertArr;

                Db::table('zstp_neo4j_rewards_punishments_event')->insertAll($insertArr);
            }

            if (empty($value['organization_name']) || !checkFields($value['organization_name'])) {

                echo "";
            } else {

                $insertArr = [];

                $subject_nameArr = explode(",", $value['organization_name']);
                var_dump($subject_nameArr);
                foreach ($subject_nameArr as $key => $v) {
                    $insert = [];
                    $insert['article_id'] = $this->article_id;
                    $insert['queue_id'] = $this->queue_id;
                    $insert['qzh'] = $this->qzh;
                    $insert['dh'] = $this->dh;
                    $insert['wjbh'] = $this->wjbh;
                    $count = 0;

                    $insert['subject_name'] = $v;

                    $insert['event_type'] = '';
                    if (!empty($value['event_type']) && checkFields($value['event_type'])) {
                        $insert['event_type'] = $value['event_type'];
                        $count++;
                    }
                    $insert['summary'] = '';
                    if (!empty($value['summary']) && checkFields($value['summary'])) {
                        $insert['summary'] = $value['summary'];
                        $count++;
                    }

                    $insert['reason'] = '';
                    if (!empty($value['reason']) && checkFields($value['reason'])) {
                        $insert['reason'] = $value['reason'];
                        $count++;
                    }

                    $insert['issuer'] = '';
                    if (!empty($value['issuer']) && checkFields($value['issuer'])) {
                        $insert['issuer'] = $value['issuer'];
                        $count++;
                    }
                    $insert['event_date'] = '';
                    if (!empty($value['event_date']) && checkFields($value['event_date'])) {
                        $insert['event_date'] = $value['event_date'];
                        $count++;
                    }
                    $insert['type'] = '2';

                    if ($count >= 1) {
                        $insertArr[] = $insert;
                    }
                }
                $this->chouData["奖惩抽取结果-组织"] = $insertArr;

                Db::table('zstp_neo4j_rewards_punishments_event')->insertAll($insertArr);
            }
        }
        return ['code' => 200, 'msg' => '处理成功'];
    }

    function historical_evolution($data)
    {
        $insertArr = [];

        foreach ($data as $key => $value) {
            $insert = [];
            $insert['article_id'] = $this->article_id;
            $insert['queue_id'] = $this->queue_id;
            $count = 0;
            if (empty($value['unit_name']) || !checkFields($value['unit_name'])) {

                return ['code' => 400, 'msg' => '组织名称不能为空'];
            }

            $insert['unit_name'] = $value['unit_name'];

            $insert['change_date'] = '';
            if (!empty($value['change_date']) &&  checkFields($value['change_date'])) {
                $insert['change_date'] = $value['change_date'];
                $count++;
            }

            $insert['change_type'] = '';
            if (!empty($value['change_type']) &&  checkFields($value['change_type'])) {
                $insert['change_type'] = $value['change_type'];
                $count++;
            }

            $insert['before_change'] = '';
            if (!empty($value['before_change']) &&  checkFields($value['before_change'])) {
                $insert['before_change'] = $value['before_change'];
                $count++;
            }
            $insert['after_change'] = '';
            if (!empty($value['after_change']) &&  checkFields($value['after_change'])) {
                $insert['after_change'] = $value['after_change'];
                $count++;
            }
            $insert['reason'] = '';
            if (!empty($value['reason']) &&  checkFields($value['reason'])) {
                $insert['reason'] = $value['reason'];
                $count++;
            }
            $insert['note'] = '';
            if (!empty($value['note']) &&  checkFields($value['note'])) {
                $insert['note'] = $value['note'];
                $count++;
            }
            $insert['commander_name'] = '';
            if (!empty($value['commander_name']) &&  checkFields($value['commander_name'])) {
                $insert['commander_name'] = $value['commander_name'];
                $count++;
            }

            $insert['former_commander_name'] = '';
            if (!empty($value['former_commander_name']) &&  checkFields($value['former_commander_name'])) {
                $insert['former_commander_name'] = $value['former_commander_name'];
                $count++;
            }

            $insert['note'] = '';
            if (!empty($value['note']) &&  checkFields($value['note'])) {
                $insert['note'] = $value['note'];
                $count++;
            }


            $insert['dh'] = $this->dh;
            $insert['wjbh'] = $this->wjbh;
            $insert['article_id'] = $this->article_id;
            $insert['queue_id'] = $this->queue_id;
            $insert['qzh'] = $this->qzh;

            if ($count >= 1) {
                $insertArr[] = $insert;
            }
        }

        $this->chouData["机构历史沿革抽取结果"] = $insertArr;

        Db::table('zstp_neo4j_historical_evolution')->insertAll($insertArr);

        return ['code' => 200, 'msg' => '处理成功'];
    }
    // 出国事件
    function abroad_event($data)
    {
        $insertArr = [];

        foreach ($data as $key => $value) {
            $insert = [];
            $insert['article_id'] = $this->article_id;
            $insert['queue_id'] = $this->queue_id;
            $count = 0;
            if (empty($value['personnel_name']) || !checkFields($value['personnel_name'])) {

                return ['code' => 400, 'msg' => '人员名称不能为空'];
            }

            $insert['personnel_name'] = $value['personnel_name'];


            $insert['country'] = '';
            if (!empty($value['country']) &&  checkFields($value['country'])) {
                $insert['country'] = $value['country'];
                $count++;
            }

            $insert['event_type'] = '';
            if (!empty($value['event_type']) &&  checkFields($value['event_type'])) {
                $insert['event_type'] = $value['event_type'];
                $count++;
            }
            $insert['abroad_date'] = '';
            if (!empty($value['abroad_date']) &&  checkFields($value['abroad_date'])) {
                $insert['abroad_date'] = $value['abroad_date'];
                $count++;
            }
            $insert['return_date'] = '';
            if (!empty($value['return_date']) &&  checkFields($value['return_date'])) {
                $insert['return_date'] = $value['return_date'];
                $count++;
            }
            $insert['reason'] = '';
            if (!empty($value['reason']) &&  checkFields($value['reason'])) {
                $insert['reason'] = $value['reason'];
                $count++;
            }

    


            $insert['dh'] = $this->dh;
            $insert['wjbh'] = $this->wjbh;
            $insert['article_id'] = $this->article_id;
            $insert['queue_id'] = $this->queue_id;
            $insert['qzh'] = $this->qzh;
            if ($count >= 1) {
                $insertArr[] = $insert;
            }




        }

        $this->chouData["出国出境记录抽取结果"] = $insertArr;

        Db::table('zstp_neo4j_abroad_event')->insertAll($insertArr);

        return ['code' => 200, 'msg' => '处理成功'];
    }

    // 社会关系
    function social_relations($data)
    {
        $insertArr = [];

        foreach ($data as $key => $value) {
            $insert = [];
            $insert['article_id'] = $this->article_id;
            $insert['queue_id'] = $this->queue_id;
            $count = 0;
            if (empty($value['name']) || !checkFields($value['name'])) {

                return ['code' => 400, 'msg' => '人员名称不能为空'];
            }

            $insert['name'] = $value['name'];

            $insert['linked_person_name'] = '';

            if (!empty($value['linked_person_name']) &&  checkFields($value['linked_person_name'])) {
                $insert['linked_person_name'] = $value['linked_person_name'];
                $count++;
            }

            $insert['relationship_type'] = '';
            if (!empty($value['relationship_type']) &&  checkFields($value['relationship_type'])) {
                $insert['relationship_type'] = $value['relationship_type'];
                $count++;
            }

            $insert['ethnicity'] = '';
            if (!empty($value['ethnicity']) &&  checkFields($value['ethnicity'])) {
                $insert['ethnicity'] = $value['ethnicity'];
                $count++;
            }

            $insert['native_place'] = '';
            if (!empty($value['native_place']) &&  checkFields($value['native_place'])) {
                $insert['native_place'] = $value['native_place'];
                $count++;
            }

            $insert['birth_date'] = '';
            if (!empty($value['birth_date']) &&  checkFields($value['birth_date'])) {
                $insert['birth_date'] = $value['birth_date'];
                $count++;
            }

            $insert['marriage_date'] = '';
            if (!empty($value['marriage_date']) &&  checkFields($value['marriage_date'])) {
                $insert['marriage_date'] = $value['marriage_date'];
                $count++;
            }

            $insert['occupation'] = '';
            if (!empty($value['occupation']) &&  checkFields($value['occupation'])) {
                $insert['occupation'] = $value['occupation'];
                $count++;
            }

            $insert['education'] = '';
            if (!empty($value['education']) &&  checkFields($value['education'])) {
                $insert['education'] = $value['education'];
                $count++;
            }

            $insert['workplace'] = '';
            if (!empty($value['workplace']) &&  checkFields($value['workplace'])) {
                $insert['workplace'] = $value['workplace'];
                $count++;
            }

            $insert['political_status'] = '';
            if (!empty($value['political_status']) &&  checkFields($value['political_status'])) {
                $insert['political_status'] = $value['political_status'];
                $count++;
            }

            $insert['with_army'] = '';
            if (!empty($value['with_army']) &&  checkFields($value['with_army'])) {
                $insert['with_army'] = $value['with_army'];
                $count++;
            }

            $insert['note'] = '';
            if (!empty($value['note']) &&  checkFields($value['note'])) {
                $insert['note'] = $value['note'];
                $count++;
            }
          $insert['gender'] = "";
          if(!empty($value['gender']) && checkFields($value['gender'])){
            $insert['gender'] = $value['gender'];
            $count++;
          }

          $insert['marital_status'] = "";
          if(!empty($value['marital_status']) && checkFields($value['marital_status'])){
            $insert['marital_status'] = $value['marital_status'];
            $count++;
          }
            $insert['dh'] = $this->dh;
            $insert['wjbh'] = $this->wjbh;
            $insert['article_id'] = $this->article_id;
            $insert['queue_id'] = $this->queue_id;
            $insert['qzh'] = $this->qzh;


            if ($count >= 1) {
                $insertArr[] = $insert;
            }
        }
        $this->chouData["社会关系抽取结果-配偶子女抽取结果"] = $insertArr;

        Db::table('zstp_neo4j_social_relations')->insertAll($insertArr);

        return ['code' => 200, 'msg' => '处理成功'];
    }
    // 军衔
    function rank_event($data)
    {



        $insertArr = [];

        foreach ($data as $key => $value) {
            $insert = [];
            $insert['article_id'] = $this->article_id;
            $insert['queue_id'] = $this->queue_id;
            $insert['qzh'] = $this->qzh;
            $count = 0;
            if (empty($value['personnel_name']) || !checkFields($value['personnel_name'])) {

                return ['code' => 400, 'msg' => '人员名称不能为空'];
            }

            $insert['personnel_name'] = $value['personnel_name'];

            $insert['event_type'] = '';

            if (!empty($value['event_type']) &&  checkFields($value['event_type'])) {
                $insert['event_type'] = $value['event_type'];
                $count++;
            }
            $insert['summary'] = "";
            if (!empty($value['summary']) &&  checkFields($value['summary'])) {
                $insert['summary'] = $value['summary'];
                $count++;
            }
            $insert['current_position'] = "";
            if (!empty($value['current_position']) &&  checkFields($value['current_position'])) {
                $insert['current_position'] = $value['current_position'];
                $count++;
            }
            $insert['department'] = "";
            $insert['department'] = "";
            if (!empty($value['department']) &&  checkFields($value['department'])) {
                $insert['department'] = $value['department'];
                $count++;
            }
            $insert['reason'] = "";
            if (!empty($value['reason']) &&  checkFields($value['reason'])) {
                $insert['reason'] = $value['reason'];
                $count++;
            }
            $insert['issuer'] = "";
            if (!empty($value['issuer']) &&  checkFields($value['issuer'])) {
                $insert['issuer'] = $value['issuer'];
                $count++;
            }

            $insert['effective_date'] = "";
            if (!empty($value['effective_date']) &&  checkFields($value['effective_date'])) {
                $insert['effective_date'] = $value['effective_date'];
                $count++;
            }

            $insert['event_date'] = "";
            if (!empty($value['event_date']) &&  checkFields($value['event_date'])) {
                $insert['event_date'] = $value['event_date'];
                $count++;
            }

            $insert['position'] = "";
            if(!empty($value['position']) && checkFields($value['position'])){
                $insert['position'] = $value['position'];
                $count++;
            }

            $insert['original_position'] = "";
            if(!empty($value['original_position']) && checkFields($value['original_position'])){
                $insert['original_position'] = $value['original_position'];
                $count++;
            }

        


            $insert['dh'] = $this->dh;
            $insert['wjbh'] = $this->wjbh;
            $insert['article_id'] = $this->article_id;
            $insert['queue_id'] = $this->queue_id;
            $insert['qzh'] = $this->qzh;

            if ($count >= 1) {
                $insertArr[] = $insert;
            }
        }

        $this->chouData["军衔/级别结果抽取"] = $insertArr;

        Db::table('zstp_neo4j_rank_event')->insertAll($insertArr);

        return ['code' => 200, 'msg' => '处理成功'];
    }
    //职位属性
    function position_event($data)
    {

        $insertArr = [];

        foreach ($data as $key => $value) {
            $insert = [];
            $insert['article_id'] = $this->article_id;
            $insert['queue_id'] = $this->queue_id;
            $count = 0;
            if (!isset($value['personnel_name']) || !checkFields($value['personnel_name'])) {

                return ['code' => 400, 'msg' => '人员名称不能为空'];
            }

            $insert['personnel_name'] = $value['personnel_name'];
            $insert['event_type'] = '';
            if (!empty($value['event_type']) &&  checkFields($value['event_type'])) {

                $insert['event_type'] = $value['event_type'];
                $count++;
            }

            $insert['original_position'] = '';
            if (!empty($value['original_position']) && checkFields($value['original_position'])) {
                $insert['original_position'] = $value['original_position'];
                $count++;
            }

            $insert['current_position'] = '';
            if (!empty($value['current_position']) && checkFields($value['current_position'])) {
                $insert['current_position'] = $value['current_position'];
                $count++;
            }


            $insert['department'] = '';
            if (!empty($value['department']) && checkFields($value['department'])) {
                $insert['department'] = $value['department'];
                $count++;
            }

            $insert['reason'] = '';
            if (!empty($value['reason']) && checkFields($value['reason'])) {
                $insert['reason'] = $value['reason'];
                $count++;
            }
            $insert['issuer'] = '';
            if (!empty($value['issuer']) && checkFields($value['issuer'])) {
                $insert['issuer'] = $value['issuer'];
                $count++;
            }

            $insert['effective_date'] = '';
            if (!empty($value['effective_date']) && checkFields($value['effective_date'])) {
                $insert['effective_date'] = $value['effective_date'];
                $count++;
            }

            $insert['event_date'] = '';
            if (!empty($value['event_date']) && checkFields($value['event_date'])) {
                $insert['event_date'] = $value['event_date'];
                $count++;
            }

            $insert['dh'] = $this->dh;
            $insert['wjbh'] = $this->wjbh;

            $insert['article_id'] = $this->article_id;
            $insert['queue_id'] = $this->queue_id;
            $insert['qzh'] = $this->qzh;

            if ($count >= 1) {
                $insertArr[] = $insert;
            }
        }

        $this->chouData["任职履历抽取结果"] = $insertArr;

        Db::table('zstp_neo4j_position_event')->insertAll($insertArr);

        return ['code' => 200, 'msg' => '处理成功'];
    }
    //组织属性
    function organization($data)
    {

     
        $insertArr = [];
        $count = 0;
        foreach ($data as $key => $value) {

            $insert = [];

            // var_dump(!isset($value['unit_name']));
            // var_dump(checkFields($value['unit_name']));

            if (empty($value['unit_name']) || !checkFields($value['unit_name'])) {

                return ['code' => 400, 'msg' => '单位名称不能为空'];
            }
            $insert['unit_name'] = $value['unit_name'];

            $insert['unit_designation'] = "";

            if (!empty($value['unit_designation']) && checkFields($value['unit_designation'])) {
                $insert['unit_designation'] = $value['unit_designation'];
                $count++;
            }

            $insert['parent_unit_name'] = "";

            if (!empty($value['parent_unit_name']) && checkFields($value['parent_unit_name'])) {
                $insert['parent_unit_name'] = $value['parent_unit_name'];
                $count++;
            }

            $insert['unit_type'] = "";

            if (!empty($value['unit_type']) && checkFields($value['unit_type'])) {
                $insert['unit_type'] = $value['unit_type'];
                $count++;
            }

            $insert['establishment_date'] = "";

            if (!empty($value['establishment_date']) && checkFields($value['establishment_date'])) {
                $insert['establishment_date'] = $value['establishment_date'];
                $count++;
            }

            $insert['area_of_responsibility'] = "";

            if (!empty($value['area_of_responsibility']) && checkFields($value['area_of_responsibility'])) {
                $insert['area_of_responsibility'] = $value['area_of_responsibility'];
                $count++;
            }

            $insert['strength'] = "";

            if (!empty($value['strength']) && checkFields($value['strength'])) {
                $insert['strength'] = $value['strength'];
                $count++;
            }

            $insert['specialization'] = "";

            if (!empty($value['specialization']) && checkFields($value['specialization'])) {
                $insert['specialization'] = $value['specialization'];
                $count++;
            }

            $insert['note'] = "";

            if (!empty($value['note']) && checkFields($value['note'])) {
                $insert['note'] = $value['note'];
                $count++;
            }
            $insert['commander_name']="";
            if(!empty($value['commander_name']) && checkFields($value['commander_name'])){
                $insert['commander_name'] = $value['commander_name'];
                $count++;
            }
      
            $insert['location']="";
            if(!empty($value['location']) && checkFields($value['location'])){
                $insert['location'] = $value['location'];
                $count++;
            }



            $insert['article_id'] = $this->article_id;
            $insert['queue_id'] = $this->queue_id;
            $insert['qzh'] = $this->qzh;
            $insert['dh'] = $this->dh;
            $insert['wjbh'] = $this->wjbh;

            if ($count >= 1) {
                $mapWhere['qzh'] = $this->qzh;
                $mapWhere['unit_name'] = $insert['unit_name'];
                $mapWhere['is_delete'] = 0;
                $mapWhere['article_id'] = $this->article_id;
                $result = Db::table('zstp_neo4j_organization')->where($mapWhere)->find();
                if (empty($result)) {
                    Db::table('zstp_neo4j_organization')->insert($insert);
                }
            }
        }

        $this->chouData["组织机构属性抽取结果"] = $insertArr;

        Db::table('zstp_neo4j_organization')->insertAll($insertArr);

        return ['code' => 200, 'msg' => '处理成功'];
    }

    //人员属性
    function personnel($data)
    {

        $insertArr = [];
        foreach ($data as $key => $value) {
            $insert = [];
            $count = 0;
            if (empty($value['name']) || !checkFields($value['name'])) {
                return ['code' => 400, 'msg' => '姓名不能为空'];
            }


            $insert['name'] = $value['name'];
            $insert['gender'] = "";

            if (!empty($value['gender']) && checkFields($value['gender'])) {
                $insert['gender'] = $value['gender'];
                $count++;
            }

            $insert['ethnicity'] = "";

            if (!empty($value['ethnicity']) && checkFields($value['ethnicity'])) {
                $insert['ethnicity'] = $value['ethnicity'];
                $count++;
            }

            $insert['political_status'] = "";


            if (!empty($value['political_status']) && checkFields($value['political_status'])) {
                $insert['political_status'] = $value['political_status'];
                $count++;
            }

            $insert['marital_status'] = "";

            if (!empty($value['marital_status']) && checkFields($value['marital_status'])) {
                $insert['marital_status'] = $value['marital_status'];
                $count++;
            }

            $insert['birth_date'] = "";

            if (!empty($value['birth_date']) && checkFields($value['birth_date'])) {
                $insert['birth_date'] = $value['birth_date'];
                $count++;
            }

            $insert['party_join_date'] = "";

            if (!empty($value['party_join_date']) && checkFields($value['party_join_date'])) {
                $insert['party_join_date'] = $value['party_join_date'];
                $count++;
            }

            $insert['enlistment_date'] = "";


            if (!empty($value['enlistment_date']) && checkFields($value['enlistment_date'])) {
                $insert['enlistment_date'] = $value['enlistment_date'];
                $count++;
            }

            $insert['discharge_date'] = "";


            if (!empty($value['discharge_date']) && checkFields($value['discharge_date'])) {
                $insert['discharge_date'] = $value['discharge_date'];
                $count++;
            }

            $insert['native_place'] = "";

            if (!empty($value['native_place']) && checkFields($value['native_place'])) {
                $insert['native_place'] = $value['native_place'];
                $count++;
            }

            $insert['education'] = "";

            if (!empty($value['education']) && checkFields($value['education'])) {
                $insert['education'] = $value['education'];
                $count++;
            }

            $insert['graduation_institution'] = "";

            if (!empty($value['graduation_institution']) && checkFields($value['graduation_institution'])) {
                $insert['graduation_institution'] = $value['graduation_institution'];
                $count++;
            }

            $insert['skills_and_expertise'] = "";


            if (!empty($value['skills_and_expertise']) && checkFields($value['skills_and_expertise'])) {
                $insert['skills_and_expertise'] = $value['skills_and_expertise'];
                $count++;
            }

            $insert['marriage_date'] = "";
            if (!empty($value['marriage_date']) && checkFields($value['marriage_date'])) {
                $insert['marriage_date'] = $value['marriage_date'];
                $count++;
            }

            $insert['occupation'] = "";
            if (!empty($value['occupation']) && checkFields($value['occupation'])) {
                $insert['occupation'] = $value['occupation'];
                $count++;
            }

            $insert['article_id'] = $this->article_id;
            $insert['queue_id'] = $this->queue_id;
            $insert['qzh'] = $this->qzh;
            $insert['dh'] = $this->dh;
            $insert['wjbh'] = $this->wjbh;

            if ($count >= 1) {
                $insertArr[] = $insert;
            
            }
        }

        $this->chouData["人物属性抽取结果"] = $insertArr;

        Db::table('zstp_neo4j_personal_attributes')->insertAll($insertArr);

        return ['code' => 200, 'msg' => '处理成功'];
    }



    function ollamaDataformat($ollamaData)
    {

        $dataArr = json_decode($ollamaData, true);
        $Json = $dataArr['message']['content'];
        $Json = getJson($Json);


        // 转成数组
        $dataArr = json_decode($Json, true);


        $keys = array_keys($dataArr);
        return array("type" => $keys[0], "data" => $dataArr[$keys[0]]);
    }


    function onlineOllamaDataformat($ollamaData)
    {

   

        $dataArr = json_decode($ollamaData, true);


    

        $Json = $dataArr['choices'][0]['message']['content'];
        $Json = getJson($Json);



        // 转成数组
        $dataArr = json_decode($Json, true);

        var_dump($dataArr);
        // die();


        $keys = array_keys($dataArr);
        return array("type" => $keys[0], "data" => $dataArr[$keys[0]]);
    }

    function ollama($cueWord)
    {

        $ch = curl_init();

        $ollamaURL =  $this->ollamaIp;

        $url = "http://{$ollamaURL}:11434/api/chat";

        $model = $this->model_name;

        $headers = [
            'Authorization: Bearer sk-tiuvcznrtvpmjnipckrwiaotbspbpeslgbxadpwznrfdqocc',
            'Content-Type: application/json'
        ];
        $data = json_encode([
            "model" =>  $model,
            "options" => ["num_ctx" => 32768, "num_predict" => 4096],
            "num_predict" => 4096, // 限制输出长度
            "messages" => [
                [
                    "role" => "system",
                    "content" => ""
                ],
                [
                    "role" => "user",
                    "content" => $cueWord,
                ]
            ],
            "stream" => false,
            "max_tokens" => 512,
            "stop" => ["<string>"],
            "temperature" => 0.7,
            "top_p" => 0.7,
            "top_k" => 50,
            "frequency_penalty" => 0.5,
            "n" => 1,
            "response_format" => ["type" => "json_object"]
        ]);

        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

        // 执行请求并获取响应
        $response = curl_exec($ch);


        if (curl_errno($ch)) {
            echo 'Error:' . curl_error($ch);
        } else {
            // 输出响应结果
            //            echo $response;
        }

        // 关闭cURL资源
        curl_close($ch);


        return $response;
    }

    public function onlineOllama($cueWord)
    {


        $ch = curl_init();


        $url = "https://api.siliconflow.cn/v1/chat/completions";

        $headers = [
            'Authorization: Bearer sk-tiuvcznrtvpmjnipckrwiaotbspbpeslgbxadpwznrfdqocc',
            'Content-Type: application/json'
        ];
        $data = json_encode([
            "model" =>  "Qwen/Qwen2.5-7B-Instruct",
            "messages" => [
                [
                    "role" => "system",
                    "content" => ""
                ],
                [
                    "role" => "user",
                    "content" => $cueWord,
                ]
            ],
          
            "max_tokens" => 1024,
            "stop" => ["<string>"],
            "temperature" => 0.7,
            "top_p" => 0.7,
            "top_k" => 50,
            "frequency_penalty" => 0.0,
          
        ]);

        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

        // 执行请求并获取响应
        $response = curl_exec($ch);


        if (curl_errno($ch)) {
            echo 'Error:' . curl_error($ch);
        } else {
            // 输出响应结果
            //            echo $response;
        }

        // 关闭cURL资源
        curl_close($ch);

  

        return $response;
    }







    function fieldAssignment($str, $fieldName)
    {

        if (!empty($str)) {
            $res = checkFields($str);
            if ($res != false) {
                $this->insertArr[$fieldName] = $res;
            }
        }
    }

    public function saveOrUptTempTest()
    {

        $data = request()->put();
        $articleResult = MyHelper::getArticleInfoById($data['article_id']);
        $content = $articleResult['data']['content'];

        $cueWord = $data['persondesc']
            . "以下是文章正文：
                $content 
            ";

        $this->model_name = "qwen2.5:7b";
        $this->ollamaIp = "172.16.95.191";
        $data = $this->ollama($cueWord);
        $dataArr = $this->ollamaDataformat($data);

        return json(['code' => 200, 'msg' => '处理成功', 'data' => $dataArr]);
    }

    function match($str, $titleIncludeArr)
    {
        if (empty($str)) {
            return false;
        }

        foreach ($titleIncludeArr as $required) {
            if (strpos($str, trim($required)) !== false) {
                return true;
            }
        }
        return false;
    }

    public function filter($article)
    {


        //查看有多少页
        $ztsl = $article['ztsl'];

        if(!empty( $ztsl )){

            if($ztsl>15){
                $updateError = array(
                    "node" => "文档页数超过15页",
                    "status" => 1,
                    "update_time" => date('Y-m-d H:i:s')
                );
                Db::table('zstp_obtain_queue')->where('id', $this->queue_id)->update($updateError);
                return true;
            }
       }

        $content = $article['content'];
        // 过滤内容
        $filteringResult = Db::table('zstp_extract_filtering')->where('id', 1)->find();
        $arrFiltering = json_decode($filteringResult['txt'], true);
        //题目必须包含的字符串
        if (!empty($arrFiltering['titleInclude'])) {
            //字符串转成数组
            $titleIncludeArr = explode(",", $arrFiltering['titleInclude']);
            // $article['tm']="2131";
            var_dump($titleIncludeArr);
            var_dump($article['tm']);
            $matchResult = $this->match($article['tm'], $titleIncludeArr);
            if (!$matchResult) {
                $updateError = array(
                    "node" => "提名({$article['tm']})不包含题目必须包含的字符串({$arrFiltering['titleInclude']})",
                    "status" => 1,
                    "update_time" => date('Y-m-d H:i:s')
                );
                Db::table('zstp_obtain_queue')->where('id', $this->queue_id)->update($updateError);
                return true;
            }
        }

        //提名必须不包含的字符串
        if (!empty($arrFiltering['titleExclude'])) {
            //字符串转成数组
            $titleExcludeArr = explode(",", $arrFiltering['titleExclude']);
            $matchResult = $this->match($article['tm'], $titleExcludeArr);
            if ($matchResult) {
                $updateError = array(
                    "node" => "提名({$article['tm']})包含必须不包含的字符串({$arrFiltering['titleExclude']})",
                    "status" => 1,
                    "update_time" => date('Y-m-d H:i:s')
                );
                Db::table('zstp_obtain_queue')->where('id', $this->queue_id)->update($updateError);
                return true;
            }
        }

        //文档内容必须包含的字符串
        if (!empty($arrFiltering['contentInclude'])) {
            //字符串转成数组
            $contentIncludeArr = explode(",", $arrFiltering['contentInclude']);
            $matchResult = $this->match($content, $contentIncludeArr);
            if (!$matchResult) {
                $updateError = array(
                    "node" => "文档内容({$content})不包含必须包含的字符串({$arrFiltering['contentInclude']})",
                    "status" => 1,
                    "update_time" => date('Y-m-d H:i:s')
                );
                Db::table('zstp_obtain_queue')->where('id', $this->queue_id)->update($updateError);
                return true;
            }
        }

        //文档内容必须不包含的字符串

        if (!empty($arrFiltering['contentExclude'])) {
            //字符串转成数组
            $contentExcludeArr = explode(",", $arrFiltering['contentExclude']);
            $matchResult = $this->match($content, $contentExcludeArr);
            if ($matchResult) {
                $updateError = array(
                    "node" => "文档内容({$content})包含必须不包含的字符串({$arrFiltering['contentExclude']})",
                    "status" => 1,
                    "update_time" => date('Y-m-d H:i:s')
                );
                Db::table('zstp_obtain_queue')->where('id', $this->queue_id)->update($updateError);
                return true;
            }
        }
    }


    function ollamaMk($cueWord)
    {
       
   

        $ch = curl_init();

        $ollamaURL =  $this->ollamaIp;
     

        $url = "http://{$ollamaURL}:11434/api/chat";

        $model = $this->model_name;
       

        $headers = [
            'Authorization: Bearer sk-tiuvcznrtvpmjnipckrwiaotbspbpeslgbxadpwznrfdqocc',
            'Content-Type: application/json'
        ];
        $data = json_encode([
            "model" =>  $model,
            "options" => ["num_ctx" => 32768, "num_predict" => 4096],
            "num_predict" => 4096, // 限制输出长度
            "messages" => [
                [
                    "role" => "system",
                    "content" => ""
                ],
                [
                    "role" => "user",
                    "content" => $cueWord,
                ]
            ],
            "stream" => false,
            "max_tokens" => 512,
            "stop" => ["<string>"],
            "temperature" => 0.7,
            "top_p" => 0.7,
            "top_k" => 50,
            "frequency_penalty" => 0.5,
            "n" => 1,
            "response_format" => ["type" => "json_object"]
        ]);

        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

        // 执行请求并获取响应
        $response = curl_exec($ch);


        if (curl_errno($ch)) {
            echo 'Error:' . curl_error($ch);
        } else {
            // 输出响应结果
            //            echo $response;
        }

        // 关闭cURL资源
        curl_close($ch);


        return $response;
    }


    public function mk($data){

 

        $dh=$data['dh'];

        $qzh=$data['qzh'];

        $map['dh']=$dh;
        $map['zstp_is_delete']= 0;

        //查文件编号
        $fileResult = Db::table('zstp_article')->field('id,wjbh')->where( $map)->find();

        if(empty($fileResult)){
            return ['code' => 400, 'msg' => '文件不存在' ,'data'=>[]];
        }   
        $wjbh=$fileResult['wjbh'];
        $article_id=$fileResult['id'];
        $queue_id=$data['id'];



         

        $cueWord = '请严格按照以下json格式输出，不能多字段也不能少字段，如果字段值未知，则直接输出为""，请严格按照样例格式输出数据，从我给你的文章中提取奖惩相关的信息填入对应的json字段中，注意所有信息必须在原文中有说体现，不能凭空捏造，同时，你只需要输出json格式的数据，不要附带有说明性质的文字,name无法确认，就不要输出记录：
 [
    {
      "name": "string", // 名字
      "gender": "string", // 性别
      "ethnicity": "string", // 名族
      "political_status":"string",//政治面貌
      "marital_status": "string", // 婚姻状态
      "marriage_date":"YYYY-MM-DD", //结婚日期
      "birth_date":"YYYY-MM-DD", //出生日期
      "party_join_date":"YYYY-MM-DD", //入党时间
      "enlistment_date":"YYYY-MM-DD", //入伍时间
      "discharge_date":"YYYY-MM-DD", //退伍时间
      "occupation": "string", // 职业
      "native_place":"string", //籍贯
      "education":"string", //学历
      "graduation_institution":"string", //毕业院校
      "skills_and_expertise":"string"//专业技能及特长
    }
]

示例验证：
输入文本：
"| 人名     | 性别 | 名族 | 政治面貌   | 婚姻状态 | 结婚日期   | 出生日期    | 入党时间    | 入伍时间 | 退伍时间 | 职业               | 籍贯     | 学历 | 毕业院校   | 专业技能及特长             |
|----------|------|------|------------|----------|------------|-------------|-------------|----------|----------|--------------------|----------|------|------------|--------------------------|
| 李剑彤   | 男   | 汉   | 中共党员   | 已婚     | 2008-05-20 | 1987-01-01  | 2010-07-01  |          |          | 项目经理 高工       | 山东济南 | 本科 | 山东大学   | 安全生产继续教育培训       |
| 唐君杰   | 男   | 汉   | 群众       | 未婚     |            | 1987-03-15  |             |          |          | 常务经理 工程师     | 江苏南京 | 硕士 | 东南大学   | 安全生产继续教育培训       |"
解析结果：
 [
        {
           
            "name": "李剑彤",
            "gender": "男",
            "ethnicity":"汉",
            "political_status":"中共党员",
            "marital_status":"已婚",
            "marriage_date":"2008-05-20",
            "birth_date":"1987-01-01",
            "party_join_date":"2010-07-01",
            "enlistment_date":"",
            "discharge_date":"",
            "occupation":"项目经理 高工",
            "native_place":"山东济南",
            "education":"本科",
            "graduation_institution":"山东大学",
            "skills_and_expertise":"安全生产继续教育培训"
        },

        {
            "name": "唐君杰",
            "gender": "男",
            "ethnicity":"汉",
            "political_status":"群众",
            "marital_status":"未婚",
            "marriage_date":"",
            "birth_date":"1987-03-15",
            "party_join_date":"",
            "enlistment_date":"",
            "discharge_date":"",
            "occupation":"常务经理 工程师",
            "native_place":"江苏南京",
            "education":"硕士",
            "graduation_institution":"东南大学",
            "skills_and_expertise":"安全生产继续教育培训"
            
        },
 ]
';
        $cueWord=$cueWord."
        "."markdownn 内容：
        ".$data['text'];

 
   
        $data= $this->ollamaMk($cueWord);

        $dataArr = json_decode($data, true);
        $content = $dataArr['message']['content'];

    
        $substring = mb_substr($content, 0, 7);
    
        if ($substring == "```json") {
            preg_match('/```json\s*([\s\S]*?)\s*```/', $content, $matches);
            $content = $matches[1];
        }

      
        $arr = json_decode($content, true);

 
        if(empty($arr)){
            return ['code' => 200, 'msg' => '解析失败' ,'data'=>[]];
        }
   

        $redata=[];

        foreach($arr as $key=>$value){

            $insert = [];
            $insert['article_id']=$article_id;
            $insert['queue_id']=$queue_id;
            $insert['wjbh']=$wjbh;
            $insert['qzh']=$qzh;
            $insert['dh']=$dh;
            $insert['type']='mk';
            $count = 0;
            if (empty($value['name']) || !checkFields($value['name'])) {
                continue;
            }
            $insert['name'] = $value['name'];

            $insert['gender'] = "";

            if (!empty($value['gender']) && checkFields($value['gender'])) {
                $insert['gender'] = $value['gender'];
                $count++;
            }
            $insert['ethnicity'] = "";
            if (!empty($value['ethnicity']) && checkFields($value['ethnicity'])) {
                $insert['ethnicity'] = $value['ethnicity'];
                $count++;
            }

            $insert['political_status'] = "";
            if (!empty($value['political_status']) && checkFields($value['political_status'])) {
                $insert['political_status'] = $value['political_status'];
                $count++;
            }

            $insert['marital_status'] = "";
            if (!empty($value['marital_status']) && checkFields($value['marital_status'])) {
                $insert['marital_status'] = $value['marital_status'];
                $count++;
            }
            $insert['birth_date'] = "";
            if (!empty($value['birth_date']) && checkFields($value['birth_date'])) {
                $insert['birth_date'] = $value['birth_date'];
                $count++;
            }
            $insert['party_join_date'] = "";
            if (!empty($value['party_join_date']) && checkFields($value['party_join_date'])) {
                $insert['party_join_date'] = $value['party_join_date'];
                $count++;
            }
            $insert['enlistment_date'] = "";
            if (!empty($value['enlistment_date']) && checkFields($value['enlistment_date'])) {
                $insert['enlistment_date'] = $value['enlistment_date'];
                $count++;
            }
            $insert['discharge_date'] = "";
            if (!empty($value['discharge_date']) && checkFields($value['discharge_date'])) {
                $insert['discharge_date'] = $value['discharge_date'];
                $count++;
            }
            $insert['native_place'] = "";
            if (!empty($value['native_place']) && checkFields($value['native_place'])) {
                $insert['native_place'] = $value['native_place'];
                $count++;
            }
            $insert['education'] = "";
            if (!empty($value['education']) && checkFields($value['education'])) {
                $insert['education'] = $value['education'];
                $count++;
            }

            $insert['graduation_institution'] = "";
            if (!empty($value['graduation_institution']) && checkFields($value['graduation_institution'])) {
                $insert['graduation_institution'] = $value['graduation_institution'];
                $count++;
            }
            $insert['skills_and_expertise'] = "";
            if (!empty($value['skills_and_expertise']) && checkFields($value['skills_and_expertise'])) {
                $insert['skills_and_expertise'] = $value['skills_and_expertise'];
                $count++;
            }
            $insert['occupation'] = "";
            if (!empty($value['occupation']) && checkFields($value['occupation'])) {
                $insert['occupation'] = $value['occupation'];
                $count++;
            }

            if($count>0){
                $redata[]=$insert;
            }


        }

        return   array("code"=>200,"data"=>$redata);

    
    }
}
